package event

import (
	"encoding/json"
	"errors"
	"fmt"
	"kop/modules/configuration/client"
	"kop/modules/configuration/configuration/attribute/attrtype"
	"kop/util/log"
)

func init() {

	var b = client.Load("StageEvent")
	if err := json.Unmarshal(b, &Configs); err != nil {
		panic(err)
	}

	log.Info("Load StageEvent.json success.")

}

type Type int8

const (
	Type1 Type = 1 // 直接发奖励
	Type2 Type = 2 // 3种选项
	Type3 Type = 3 // 派出船长
)

type Conf struct {
	EventID       int32             `json:"ID"` // 任务ID
	EventType     Type              // 事件类型
	Weight        int32             // 权重
	NeedCamp      int32             // 阵营要求
	NeedSex       int32             // 性别要求
	NeedAttribute attrtype.AttrType // 属性类型
	AwardID       []int32           // 奖励ID
	AwardGold     []float64
	AwardCoin     []float64
}

func (c Conf) GetWeight() int32 {
	return c.Weight
}

func (c Conf) GetID() int32 {
	return c.EventID
}

var (
	Configs = map[int32]Conf{}
)

func GetEventByID(ID int32) (Conf, error) {

	var conf, ok = Configs[ID]
	if ok {
		return conf, nil
	}

	return Conf{}, errors.New(fmt.Sprintf("EventID not found [%d]", ID))
}
